package com.ruoyi.config;


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 通过TCP对接plc设备配置
 */

@Configuration
@ConfigurationProperties(prefix = "spring.plc")
public class PLCSetting {

    /**
     * PLC设备列表
     */
    private List<Device> devices;

    public List<Device> getDevices() {
        return devices;
    }

    public void setDevices(List<Device> devices) {
        this.devices = devices;
    }

    public static class Device {

        /**
         * PLC设备IP地址
         */
        private String ip;

        /**
         * PLC设备端口
         */
        private Integer port;

        /**
         * 连接超时，单位：毫秒<br/>
         * 默认5000ms
         */
        private Integer connectTimeout = 5000;

        /**
         * 默认0
         */
        private Integer rack = 0;

        /**
         * 默认1
         */
        private Integer slot = 1;

        /**
         * 一个设备可以包含多个数据块
         */
        List<DataBlock> dataBlock;

        public String getIp() {
            return ip;
        }

        public void setIp(String ip) {
            this.ip = ip;
        }

        public Integer getPort() {
            return port;
        }

        public void setPort(Integer port) {
            this.port = port;
        }

        public Integer getConnectTimeout() {
            return connectTimeout;
        }

        public void setConnectTimeout(Integer connectTimeout) {
            this.connectTimeout = connectTimeout;
        }

        public Integer getRack() {
            return rack;
        }

        public void setRack(Integer rack) {
            this.rack = rack;
        }

        public Integer getSlot() {
            return slot;
        }

        public void setSlot(Integer slot) {
            this.slot = slot;
        }

        public List<DataBlock> getDataBlock() {
            return dataBlock;
        }

        public void setDataBlock(List<DataBlock> dataBlock) {
            this.dataBlock = dataBlock;
        }
    }

    public static class DataBlock {

        /**
         * PLC数据块编号
         */
        private Integer databaseNumber;

        /**
         * 偏移量 默认为0
         */
        private Integer offset = 0;

        /**
         * 是否轮询、重复读取数据，默认：true
         */
        private boolean readRepeat = true;

        /**
         * 数据读取间隔，单位毫秒,默认100ms
         */
        private Integer readRepeatInterval = 100;

        /**
         * 数据对应的实体类对象全路径，数据实体配置数据地址偏移量、长度等相关信息
         */
        private String entityClassName;


        public Integer getDatabaseNumber() {
            return databaseNumber;
        }

        public void setDatabaseNumber(Integer databaseNumber) {
            this.databaseNumber = databaseNumber;
        }

        public Integer getOffset() {
            return offset;
        }

        public void setOffset(Integer offset) {
            this.offset = offset;
        }

        public boolean isReadRepeat() {
            return readRepeat;
        }

        public void setReadRepeat(boolean readRepeat) {
            this.readRepeat = readRepeat;
        }

        public Integer getReadRepeatInterval() {
            return readRepeatInterval;
        }

        public void setReadRepeatInterval(Integer readRepeatInterval) {
            this.readRepeatInterval = readRepeatInterval;
        }

        public String getEntityClassName() {
            return entityClassName;
        }

        public void setEntityClassName(String entityClassName) {
            this.entityClassName = entityClassName;
        }
    }
}